//package com.bbx.taxi.client.Fragment.ChangeOrder;
//
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.graphics.Color;
//import android.graphics.drawable.BitmapDrawable;
//import android.os.AsyncTask;
//import android.os.Bundle;
//import android.os.Handler;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.WindowManager.LayoutParams;
//import android.view.animation.Animation;
//import android.view.animation.AnimationUtils;
//import android.view.animation.Animation.AnimationListener;
//import android.widget.AdapterView;
//import android.widget.Button;
//import android.widget.CheckBox;
//import android.widget.CompoundButton;
//import android.widget.LinearLayout;
//import android.widget.ListView;
//import android.widget.PopupWindow;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//import android.widget.Toast;
//import android.widget.AdapterView.OnItemClickListener;
//import android.widget.CompoundButton.OnCheckedChangeListener;
//import butterknife.InjectView;
//import butterknife.InjectViews;
//
//import com.bbx.androidapi.util.ToastUtil;
//import com.bbx.api.gclient.GMsg;
//import com.bbx.api.gclient.msg.CouponMsg;
//import com.bbx.api.sdk.model.comm.returns.line.To_Cities;
//import com.bbx.api.sdk.model.passanger.CouponUsable;
//import com.bbx.api.sdk.model.passanger.MyOrder;
//import com.bbx.api.sdk.model.passanger.Order;
//import com.bbx.api.sdk.model.passanger.OrderSubmit;
//import com.bbx.api.sdk.model.passanger.PriceBuild;
//import com.bbx.api.sdk.model.passanger.Return.ChangeOrderId;
//import com.bbx.api.sdk.model.passanger.Return.Elements;
//import com.bbx.api.sdk.model.passanger.Return.OrderDetails;
//import com.bbx.api.sdk.model.passanger.Return.OrderId;
//import com.bbx.api.sdk.model.passanger.Return.Price;
//import com.bbx.api.sdk.model.passanger.Return.Coupon.CouponList;
//import com.bbx.api.sdk.model.passanger.Return.Coupon.Coupons;
//import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.End;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Location;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Locations;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrders;
//import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Start;
//import com.bbx.api.sdk.net.base.JsonBuild;
//import com.bbx.api.sdk.net.passeger.conn.ChangeOrderSubmitNet;
//import com.bbx.api.sdk.net.passeger.conn.CouponUsableNet;
//import com.bbx.api.sdk.net.passeger.conn.MyOrderNet_Unfini;
//import com.bbx.api.sdk.net.passeger.conn.OrderDetailNet;
//import com.bbx.api.sdk.net.passeger.conn.OrderSubmitNet;
//import com.bbx.api.sdk.net.passeger.conn.PriceNet;
//import com.bbx.taxi.client.Task.BaseAsyncTask;
//import com.bbx.taxi.client.MyApplication;
//import com.bbx.taxi.official.R;
//import com.bbx.taxi.client.Activity.ContactPersonActivity;
//import com.bbx.taxi.client.Activity.DetailsOfGoodsActivity;
//import com.bbx.taxi.client.Activity.MainActivity;
//import com.bbx.taxi.client.Activity.Address.EditAddressActivity;
//import com.bbx.taxi.client.Activity.Base.BaseBBXActivity;
//import com.bbx.taxi.client.Activity.Menu.ClauseActivity;
//import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
//import com.bbx.taxi.client.Activity.Order.ChangeOrderActivity;
//import com.bbx.taxi.client.Activity.Order.StartServiceActivity;
//import com.bbx.taxi.client.Bean.Value;
//import com.bbx.taxi.client.Bean.Attribute.ChangeAttribute;
//import com.bbx.taxi.client.Bean.Attribute.ChangeAttribute.OnContentFillingListener;
//import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
//import com.bbx.taxi.client.Bean.Extra.AddressMsg;
//import com.bbx.taxi.client.Bean.Extra.ClauseMsg;
//import com.bbx.taxi.client.Bean.Extra.ContactPersonMsg;
//import com.bbx.taxi.client.Bean.Extra.MainMsg;
//import com.bbx.taxi.client.Bean.Extra.OrderMsg;
//import com.bbx.taxi.client.DB.AddressDB;
//import com.bbx.taxi.client.DB.JmsgDB;
//import com.bbx.taxi.client.DB.LineDB;
//import com.bbx.taxi.client.DB.MyOrder.MyOrderDB;
//import com.bbx.taxi.client.DB.MyOrder.MyOrderLocationsDB;
//import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
//import com.bbx.taxi.client.Util.DateFormat;
//import com.bbx.taxi.client.Util.FormatUtil;
//import com.bbx.taxi.client.Util.NetworkDetector;
//import com.bbx.taxi.client.Util.ToCity;
//import com.bbx.taxi.client.widget.pop.DatePicker;
//import com.bbx.taxi.client.widget.pop.DatePicker.OnDateConfirmListener;
//import com.bbx.taxi.client.widget.pop.DatePicker.OnDateScrollResultListener;
//import com.bbx.taxi.client.widget.pop.DatePicker.OnPoPViewStateListener;
//import com.example.loadview.LoadingDialog;
//import com.example.mydatepicker.wheelview.WheelView;
//
//public class ChangeExpressActivity extends BaseBBXActivity implements
//		OnContentFillingListener, OnPoPViewStateListener {
//	@InjectView(R.id.tv_time)
//	TextView tv_time;
//	@InjectView(R.id.tv_clause)
//	TextView tv_clause;
//	@InjectView(R.id.layout_start_address)
//	RelativeLayout layout_start_address;
//	@InjectView(R.id.layout_end_address)
//	RelativeLayout layout_end_address;
//	@InjectView(R.id.layout_start_person)
//	RelativeLayout layout_start_person;
//	@InjectView(R.id.layout_end_person)
//	RelativeLayout layout_end_person;
//	@InjectView(R.id.timelayout)
//	RelativeLayout timelayout;
//	@InjectView(R.id.layout_goods)
//	RelativeLayout layout_goods;
//	@InjectView(R.id.tv_start_address)
//	TextView tv_start_address;
//	@InjectView(R.id.tv_end_address)
//	TextView tv_end_address;
//	@InjectView(R.id.tv_start_person)
//	TextView tv_start_person;
//	@InjectView(R.id.tv_end_person)
//	TextView tv_end_person;
//	@InjectView(R.id.tv_goods)
//	TextView tv_goods;
//	@InjectView(R.id.tv_message)
//	TextView tv_message;
//	@InjectView(R.id.cb_clause)
//	CheckBox cb_clause;
//	@InjectView(R.id.btn_confirm)
//	Button btn_confirm;
//	@InjectView(R.id.pop_background)
//	View pop_background;
//	/** 修改界面的信息临时存储 */
//	private ChangeAttribute change_attribute;
//	private ChangeOrderSubmitTask mChangeOrderSubmitTask;
//	private MyApplication mApplication;
//	/** 可用优惠劵 */
//	private List<Coupons> list_available = new ArrayList<Coupons>();
//	/** 是否点开可用优惠劵 */
//	private boolean isOpenAvailable = false;
//	private MyOrderingDB db_myordering;// 我的进行中的订单数据库
//	private MyOrderDB db_myorder;// 我的进行中的订单数据库
//	private AddressDB db_address;// 我的地址
//	private MyOrderLocationsDB db_locations;// 我的订单的Locations数据库
//	private LineDB db_line;// 线路数据库
//	private String old_order_id;
//	/** 生成可用优惠劵 */
//	private CouponUsableTask mCouponUsableTask;
//	/** 价格 */
//	private PriceTask mPriceTask;
//	String line_id = "";
//	int coupon_id = 0;
//	private LoadingDialog dialog;
//	List<Elements> elements;
//	protected void onCreate(Bundle savedInstanceState) {
//		setContentView(R.layout.activity_express);
//		super.onCreate(savedInstanceState);
//		
//
//	}
//
//	@Override
//	protected void initView() {
//		setTitle(context.getString(R.string.change_title));
//		dialog = new LoadingDialog(context);
//		DatePicker.setOnPoPViewStateListener(this);
//		db_myordering = new MyOrderingDB(this);
//		db_myorder = new MyOrderDB(this);
//		db_locations = new MyOrderLocationsDB(this);
//		db_line = new LineDB(this);
//		db_address=new AddressDB(this);
//		mApplication = MyApplication.getInstance();
//		change_attribute = ChangeAttribute.getInstance();
//		layout_start_address.setOnClickListener(this);
//		layout_end_address.setOnClickListener(this);
//		layout_start_person.setOnClickListener(this);
//		layout_end_person.setOnClickListener(this);
//		timelayout.setOnClickListener(this);
//		layout_goods.setOnClickListener(this);
//		btn_confirm.setOnClickListener(this);
//		tv_clause.setOnClickListener(this);
//		tv_time.setText(change_attribute.getTime());
//		cb_clause.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//
//			@Override
//			public void onCheckedChanged(CompoundButton arg0, boolean isCheck) {
//				change_attribute.setIsCBclause(isCheck);
//			}
//		});
//		Intent intent = getIntent();
//		old_order_id = intent.getStringExtra(OrderMsg.change_old_order_id);
//		///////////////////
//		initAttribute();
//		change_attribute.setOnContentFillingListener(this);
//	}
//
//	@Override
//	protected void initData() {
//		// TODO Auto-generated method stub
//
//	}
//
//	private void initAttribute() {
//		if (change_attribute.getStartName() != null
//				&& !change_attribute.getStartName().equals("")) {
//			tv_start_address.setText(change_attribute.getStartName());
//		}
//		tv_start_address.setText(change_attribute.getStartName());
//		if (change_attribute.getEndName() != null
//				&& !change_attribute.getEndName().equals("")) {
//			tv_end_address.setText(change_attribute.getEndName());
//		}
//		if (change_attribute.getName() != null
//				&& change_attribute.getTel() != null
//				&& !change_attribute.getTel().equals("")) {
//			tv_start_person
//					.setText((change_attribute.getName().equals("") ? context.getString(R.string.i)
//							: change_attribute.getName())
//							+ "-"
//							+ FormatUtil.onFormatTelephone(change_attribute
//									.getTel()));
//		}
//		if (change_attribute.getName2() != null
//				&& !change_attribute.getName2().equals("")) {
//			tv_end_person.setText(change_attribute.getName2() + "-"
//					+ FormatUtil.onFormatTelephone(change_attribute.getTel2()));
//		}
//		// 物品
//		if (change_attribute.getGoodsWeight() == 0
//				|| change_attribute.getGoodsVolume() == 0) {
//		} else {
//			String weight = "";
//			String volume = "";
//			switch (change_attribute.getGoodsVolume()) {
//			case Value.KJ_VOLUME_S:
//				volume = this.getString(R.string.goods_small);
//				break;
//			case Value.KJ_VOLUME_M:
//				volume = this.getString(R.string.goods_middle);
//				break;
//			case Value.KJ_VOLUME_B:
//				volume = this.getString(R.string.goods_big);
//				break;
//			}
//			if (change_attribute.getGoodsWeight() == Value.KJ_WEIGHT_0_5) {
//				weight = this.getString(R.string.kg_0_5);
//			} else if (change_attribute.getGoodsWeight() == Value.KJ_WEIGHT_6_10) {
//				weight = this.getString(R.string.kg_6_10);
//			} else if (change_attribute.getGoodsWeight() == Value.KJ_WEIGHT_11_15) {
//				weight = this.getString(R.string.kg_11_15);
//			}
//			tv_goods.setText(weight + ";" + volume + ";");
//		}
//		// 留言
//		if (change_attribute.getGoodsWeight() == 0
//				|| change_attribute.getGoodsVolume() == 0
//				|| change_attribute.getMessage_KJ().equals("")) {
//			tv_message.setVisibility(View.GONE);
//		} else {
//			tv_message.setVisibility(View.VISIBLE);
//			tv_message.setText(change_attribute.getMessage_KJ());
//		}
//		onContentFilling();
//	}
//
//	@Override
//	public void onClick(View v) {
//		switch (v.getId()) {
//		case R.id.tv_clause:
//			startActivity(new Intent(this, ClauseActivity.class).putExtra(
//					ClauseMsg.extra_clause, ClauseMsg.CLAUSE_KJ));
//			break;
//		case R.id.layout_start_person:
//			startActivityForResult(
//					new Intent(this, ContactPersonActivity.class).putExtra(
//							ContactPersonMsg.extra_contact_name,
//							change_attribute.getName()).putExtra(
//							ContactPersonMsg.extra_contact_phone,
//							change_attribute.getTel()),
//					MainAttribute.REQUEST_CODE_PERSON);
//			break;
//		case R.id.layout_end_person:
//			startActivityForResult(
//					new Intent(this, ContactPersonActivity.class).putExtra(
//							ContactPersonMsg.extra_contact_name,
//							change_attribute.getName2()).putExtra(
//							ContactPersonMsg.extra_contact_phone,
//							change_attribute.getTel2()),
//					MainAttribute.REQUEST_CODE_PERSON2);
//			break;
//		case R.id.layout_start_address:
//			startActivityForResult(
//					new Intent(this, EditAddressActivity.class).putExtra(
//							AddressMsg.extra_editaddress,
//							AddressMsg.ADDRESS_START_CHANGE),
//					MainAttribute.REQUEST_CODE_START_ADDRESS);
//			break;
//		case R.id.layout_end_address:
//			startActivityForResult(
//					new Intent(this, EditAddressActivity.class).putExtra(
//							AddressMsg.extra_editaddress,
//							AddressMsg.ADDRESS_END_CHANGE),
//					MainAttribute.REQUEST_CODE_END_ADDRESS);
//			break;
//		case R.id.timelayout:
//			DatePicker.getInstance(this).onShow(v, 2);
//			DatePicker.getInstance(this).setOnDateScrollResultListener(
//					new OnDateScrollResultListener() {
//						@Override
//						public void OnDateScrollResult(List<String> list,
//								WheelView wl_day, WheelView wl_hour,
//								WheelView wl_min) {
//							switch (wl_day.getCurrentItem()) {
//							case 0://
//								wl_hour.setCurrentItem(0, true);
//								wl_min.setCurrentItem(0, true);
//								break;
//							case 1:// 今天，滑动到当前时间
//								long Time = DateFormat.getTime() + 20 * 60 * 1000;// 加20分上去，是为了不让选择当前时间+20分以下的时间
//								Calendar mCalendar = Calendar.getInstance();
//								mCalendar.setTimeInMillis(Time);
//								int hour = mCalendar.get(Calendar.HOUR_OF_DAY);
//								int minute = mCalendar.get(Calendar.MINUTE);
//								if ((wl_hour.getCurrentItem() - 1) <= (hour)) {
//									wl_hour.setCurrentItem(hour + 1, true);
//									if ((wl_min.getCurrentItem() - 1) <= (minute)) {
//										wl_min.setCurrentItem(minute + 1, true);
//									}
//								}
//								break;
//							default:
//								if (wl_hour.getCurrentItem() == 0) {
//									wl_hour.setCurrentItem(1, true);
//								}
//								if (wl_min.getCurrentItem() == 0) {
//									wl_min.setCurrentItem(1, true);
//								}
//								break;
//							}
//						}
//					});
//			DatePicker.getInstance(this).setOnDateConfirmListener(
//					new OnDateConfirmListener() {
//						@Override
//						public void onDateConfirm(List<String> list,
//								WheelView wl_day, WheelView wl_hour,
//								WheelView wl_min) {
//							if (wl_day.getCurrentItem() == 0) {
//								change_attribute.setTime(list.get(wl_day
//										.getCurrentItem()));
//								tv_time.setText(change_attribute.getTime());
//								return;
//							}
//							change_attribute.setTime(DatePicker.getInstance(
//									ChangeExpressActivity.this).onTimeFormat(
//									list.get(wl_day.getCurrentItem()),
//									wl_hour.getCurrentItem() - 1,
//									wl_min.getCurrentItem() - 1));
//							tv_time.setText(change_attribute.getTime());
//						}
//					});
//			break;
//		case R.id.layout_goods:
//			startActivityForResult(new Intent(this,
//					DetailsOfGoodsActivity.class).putExtra(
//					MainMsg.extra_message, MainMsg.MESSAGE_CHANGE_KJ),
//					MainAttribute.REQUEST_CODE_GOODS);
//			break;
//		case R.id.btn_confirm:
//			getPrice(v);
//			break;
//		default:
//			super.onClick(v);
//			break;
//		}
//
//	}
//	/**
//	 * 判断是否有改动
//	 */
//	public String isChange(){
//		String tixing="";
//		String no_change=this.getResources().getString(R.string.order_no_change);
//		tixing=no_change;
//		MyOrderList mMyOrderList=db_myorder.onReadDB(context, old_order_id);
//		Locations mLocations = mMyOrderList.getLocations();
//		//判断时间
//		if(change_attribute.getTime().equals(Value.now_time)){
//			tixing="";
//		}
//		if(Math.abs(DateFormat.onDate_Long(mMyOrderList.getAppoint_time())-DateFormat.onDate_Long(change_attribute.getTime()))>1000*60){
//			tixing="";
//		}
//		//判断地址
//		if(!mLocations.getStart().getAddress().equals(change_attribute.getStartName())){
//			tixing="";
//		}
//		if(!mLocations.getEnd().getAddress().equals(change_attribute.getEndName())){
//			tixing="";
//		}
//		//判断名字
//		if(!mLocations.getStart().getName().equals(change_attribute.getName())){
//			tixing="";
//		}
//		//判断电话
//		if(!mLocations.getStart().getPhone().equals(change_attribute.getTel())){
//			tixing="";
//		}
//		//判断人数
//		if(mLocations.getCount()!=change_attribute.getCount())
//		{
//			tixing="";
//		}
//		//判断拼车留言
//		if(!mMyOrderList.getMessage().equals(change_attribute.getMessage_KJ())){
//			tixing="";
//		}
//		//判断体重
//		if(Integer.parseInt(mLocations.getVolume())!=change_attribute.getGoodsVolume()){
//			tixing="";
//		}
//		if(Integer.parseInt(mLocations.getWeight())!=change_attribute.getGoodsWeight()){
//			tixing="";
//		}
//		if(mMyOrderList.getOrder_status()>=Value.ORDER_STATUS_ONCAR){
//			tixing=this.getResources().getString(R.string.order_status_no_change);
//		}
//		return tixing;
//	}
//	/**
//	 * 获取价格
//	 */
//	public void getPrice(View v) {
//		if(!isChange().equals("")){
//    		ToastUtil.showToast(context, isChange());
//    		return;
//    	}
//		if (!NetworkDetector.detect(this)) {
//			ToastUtil.showToast(context,
//					getResources().getString(R.string.no_network));
//			return;
//		}
//		boolean isContinue = false;// 根据城市，是否有这条路线，有则继续
//		ArrayList<To_Cities> to_citylist =ToCity.getToCity(context, change_attribute.getStartCity(),false);
//		line_id=ToCity.getLine(to_citylist, change_attribute.getEndCity());
//		if(line_id!=null){
//			isContinue = true;
//		}
//		if (!isContinue) {
//			ToastUtil.showToast(context, R.string.no_support_line);
//			return;
//		}
//		setElements();
//		PriceBuild mPriceBuild = new PriceBuild(context);
//		mPriceBuild.uid = mApplication.getUid();
//		mPriceBuild.access_token = mApplication.getToken();
//		mPriceBuild.line_id = line_id;
//		mPriceBuild.order_type = Value.ORDER_TYPE_KJ;
//		mPriceBuild.elements=elements;
//		if (dialog != null && !dialog.isShowing()) {
//			dialog.show();
//		}
//		mPriceTask = new PriceTask(this, mPriceBuild, v);
//		mPriceTask.execute();
//
//	}
//
//	/**
//	 * 生成可用优惠劵
//	 */
//	public void getCouponUsable(int price, View v) {
//		CouponUsable mCouponUsable = new CouponUsable(context);
//		mCouponUsable.uid = mApplication.getUid();
//		mCouponUsable.access_token = mApplication.getToken();
//		Date date = new Date();
//		mCouponUsable.ordertime = DateFormat.onDate_Long(change_attribute
//				.getTime()) / 1000;
//		mCouponUsable.ordersum = 0;
//		mCouponUsable.ordertype = Value.ORDER_TYPE_KJ;
//		mCouponUsable.lineid = line_id;
//		mCouponUsableTask = new CouponUsableTask(context, mCouponUsable, price,
//				v);
//		mCouponUsableTask.execute();
//	}
//
//	/**
//	 * 获取价格
//	 * 
//	 */
//	private class PriceTask extends BaseAsyncTask {
//
//		private PriceBuild mPriceBuild;
//
//		private View v;
//
//		public PriceTask(Activity context, PriceBuild mPriceBuild, View v) {
//			super(context, false);
//			this.mPriceBuild = mPriceBuild;
//			this.v = v;
//		}
//
//		@Override
//		public void onSuccess(Object object) {
//			if(object!=null){
//				Price price=(Price)object;
//				getCouponUsable(price.getPrice(),v);
//			}
//			else{
//				ToastUtil.showToast(context, getResources().getString(R.string.no_network));
//				if (dialog != null) {
//					dialog.onDismiss();
//				}
//			}
//		}
//
//		@Override
//		public void onFailed(int status, String msg) {
//			ToastUtil.showToast(context,
//					getResources().getString(R.string.no_network));
//			if (dialog != null) {
//				dialog.onDismiss();
//			}
//		}
//
//		@Override
//		protected Object doInBackground(Object... params) {
//			// TODO Auto-generated method stub
//			String json = new JsonBuild().setModel(mPriceBuild).getJson();
//			return new PriceNet(context, json);
//		}
//	}
//
//	/**
//	 * 可用优惠劵
//	 * 
//	 */
//	private class CouponUsableTask extends BaseAsyncTask {
//
//		private CouponUsable mCouponUsable;
//
//		private View v;
//
//		private int price;
//
//		public CouponUsableTask(Activity context, CouponUsable mCouponUsable,
//				int price, View v) {
//			super(context, false);
//			this.mCouponUsable = mCouponUsable;
//			this.v = v;
//			this.price = price;
//			setIsReturnString(true);
//		}
//
//		@Override
//		public void onSuccess(Object object) {
//			if (object != null) {
//				CouponList mCouponList = new CouponList();
//				JSONArray ja_CouponList;
//				try {
//					List<Coupons> coupons_list = new ArrayList<Coupons>();
//					JSONObject json = new JSONObject((String) object);
//					ja_CouponList = json.getJSONArray(CouponMsg.msg_coupons);
//					for (int i = 0; i < ja_CouponList.length(); i++) {
//						Coupons mCoupons = new Coupons();
//						JSONObject jo = new JSONObject(ja_CouponList.get(i)
//								.toString());
//						mCoupons.setId(Integer.parseInt(jo
//								.getString(CouponMsg.msg_id)));
//						mCoupons.setSum(Integer.parseInt(jo.getString(CouponMsg.msg_sum)));
//						mCoupons.setExpire_time(jo
//								.getString(CouponMsg.msg_expire_time));
//						JSONObject jo_metadata = new JSONObject(
//								jo.getString(CouponMsg.msg_metadata));
//						Metadata mMetadata = new Metadata();
//
//						JSONArray ja_line =new JSONArray(jo_metadata.getString(CouponMsg.msg_usableline));
//						List<String> list_line=new ArrayList<String>();
//						for(int j=0;j<ja_line.length();j++){
//							String str_line=ja_line.get(j).toString();
//							list_line.add(str_line);
//						}
//						mMetadata.setUsableline(list_line);
//						
//						mMetadata.setUsabletype(jo_metadata
//								.getString(CouponMsg.msg_usabletype));
//						mMetadata.setUsableorder(jo_metadata
//								.getString(CouponMsg.msg_usableorder));
//						mMetadata.setUsabletime(jo_metadata
//								.getString(CouponMsg.msg_usabletime));
//						mCoupons.setMetadata(mMetadata);
//						coupons_list.add(mCoupons);
//					}
//					mCouponList.setCouponList(coupons_list);
//				} catch (JSONException e) {
//				}
//				list_available.clear();
//				if (mCouponList != null && mCouponList.getCouponList() != null
//						&& !mCouponList.getCouponList().isEmpty()) {
//					list_available.addAll(mCouponList.getCouponList());
//					onShowSubmitPopView(price, v);
//				} else {
//					onShowSubmitPopView(price, v);
//				}
//				if (dialog != null) {
//					dialog.onDismiss();
//				}
//
//			}
//		}
//
//		@Override
//		public void onFailed(int status, String msg) {
//			onShowSubmitPopView(price, v);
//			if (dialog != null) {
//				dialog.onDismiss();
//			}
//		}
//
//		@Override
//		protected Object doInBackground(Object... params) {
//			// TODO Auto-generated method stub
//			String json = new JsonBuild().setModel(mCouponUsable).getJson();
//			return new CouponUsableNet(context, json);
//		}
//	}
//
//	/**
//	 * 提交POPview
//	 */
//	private void onShowSubmitPopView(final int price, View v) {
////		coupon_id = 0;
////		View view = LayoutInflater.from(context).inflate(R.layout.pop_submit,
////				null);
////		final PopupWindow pop_submit = new PopupWindow(view,
////				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
////		pop_submit.setBackgroundDrawable(new BitmapDrawable());
////		pop_submit.setContentView(view);
////		pop_submit.setOutsideTouchable(false);
////		pop_submit.setFocusable(true);
////		pop_submit.showAtLocation(v, Gravity.CENTER, 0, 0);
////		TextView tv_price = (TextView) view.findViewById(R.id.tv_price);
////		tv_price.setText(FormatUtil.onFormatPrice(price));
////		final LinearLayout layout = (LinearLayout) view
////				.findViewById(R.id.layout);
////		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_in);
////		layout.startAnimation(a);
////		final ListView listview = (ListView) view.findViewById(R.id.listview);
////		final AvailableCouponsAdapter mAvailableCouponsAdapter = new AvailableCouponsAdapter(
////				this, list_available);
////		listview.setAdapter(mAvailableCouponsAdapter);
////		// 选择可用的优惠劵
////		final RelativeLayout layout_choice_available = (RelativeLayout) view
////				.findViewById(R.id.layout_choice_available);
////		final TextView tv_choice_available = (TextView) view
////				.findViewById(R.id.tv_choice_available);
////		// 选中的优惠劵
////		final TextView tv_selected = (TextView) view
////				.findViewById(R.id.tv_selected);
////		if (mAvailableCouponsAdapter.getCount() != 0) {
////			layout_choice_available.setVisibility(View.VISIBLE);
////			tv_choice_available.setVisibility(View.VISIBLE);
////			mAvailableCouponsAdapter.isSelected.put(0, true);
////			tv_selected.setText(String.format(context.getString(R.string.used_coupon), list_available.get(0).getSum()));
////			coupon_id = list_available.get(0).getId();
////		}
////		listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
////		listview.setOnItemClickListener(new OnItemClickListener() {
////			@Override
////			public void onItemClick(AdapterView<?> arg0, View v, int position,
////					long arg3) {
////				if (list_available.get(position).getSum().equals("0")) {
////					tv_selected.setText(context.getString(R.string.no_used_coupon));
////				} else {
////					tv_selected.setText(String.format(context.getString(R.string.used_coupon),list_available.get(position).getSum()));
////				}
////				coupon_id = list_available.get(position).getId();
////				
////				for (int i = 0; i < list_available.size(); i++) {
////					if (i == position) {
////						mAvailableCouponsAdapter.isSelected.put(i, true);
////					} else {
////						mAvailableCouponsAdapter.isSelected.put(i, false);
////					}
////				}
////				mAvailableCouponsAdapter.notifyDataSetInvalidated();
////				ViewHolder vHollder = (ViewHolder) v.getTag();
////				// 在每次获取点击的item时将对于的checkbox状态改变，同时修改map的值。
////				if(!vHollder.cb_available.isChecked()){
////			    	vHollder.cb_available.toggle();
////				}
////				new Handler().postDelayed(new Runnable() {		
////					@Override
////					public void run() {
////						listview.setVisibility(View.GONE);
////						layout_choice_available.setBackgroundDrawable(context
////								.getResources().getDrawable(R.drawable.bg_yhq2));
////						isOpenAvailable = false;
////					}
////				}, 10);
////				
////			}
////		});
////		layout_choice_available.setOnClickListener(new OnClickListener() {
////			@Override
////			public void onClick(View v) {
////				if (list_available.size() == 0)
////					return;
////				isOpenAvailable = isOpenAvailable ? false : true;
////				if (isOpenAvailable) {
////					listview.setVisibility(View.VISIBLE);
////					mAvailableCouponsAdapter.notifyDataSetChanged();
////					layout_choice_available.setBackgroundDrawable(context
////							.getResources().getDrawable(R.drawable.bg_yhq1));
////				} else {
////					listview.setVisibility(View.GONE);
////					layout_choice_available.setBackgroundDrawable(context
////							.getResources().getDrawable(R.drawable.bg_yhq2));
////				}
////
////			}
////		});
////		// 不允许
////		((Button) view.findViewById(R.id.btn_no_allow))
////				.setOnClickListener(new OnClickListener() {
////
////					@Override
////					public void onClick(View v) {
////						Animation a = AnimationUtils.loadAnimation(context,
////								R.anim.dialog_out);
////						layout.startAnimation(a);
////						a.setAnimationListener(new AnimationListener() {
////
////							@Override
////							public void onAnimationStart(Animation anim) {
////							}
////
////							@Override
////							public void onAnimationRepeat(Animation anim) {
////							}
////
////							@Override
////							public void onAnimationEnd(Animation anim) {
////								new Handler().post(new Runnable() {
////									@Override
////									public void run() {
////										pop_submit.dismiss();
////									}
////								});
////							}
////						});
////					}
////				});
////		// 允许
////		((Button) view.findViewById(R.id.btn_allow))
////				.setOnClickListener(new OnClickListener() {
////
////					@Override
////					public void onClick(View v) {
////						// confirm.setClickable(false);
////						onOrderSubmit(price);
////						Animation a = AnimationUtils.loadAnimation(context,
////								R.anim.dialog_out);
////						layout.startAnimation(a);
////						a.setAnimationListener(new AnimationListener() {
////
////							@Override
////							public void onAnimationStart(Animation anim) {
////							}
////
////							@Override
////							public void onAnimationRepeat(Animation anim) {
////							}
////
////							@Override
////							public void onAnimationEnd(Animation anim) {
////								new Handler().post(new Runnable() {
////									@Override
////									public void run() {
////										pop_submit.dismiss();
////									}
////								});
////							}
////						});
////					}
////				});
//	}
//
//	public void onActivityResult(int requestCode, int resultCode, Intent data) {
//		switch (requestCode) {
//		case MainAttribute.REQUEST_CODE_PERSON:
//			if (data != null) {
//				change_attribute.setStart_need_sms(data.getIntExtra("need_sms",
//						1));
//				String name = data.getStringExtra("name");
//				String tel = data.getStringExtra("telephone");
//				if (name != null && tel != null && !name.equals("")
//						&& !tel.equals("")) {
//					change_attribute.setTel(tel);
//					change_attribute.setName(name);
//					tv_start_person.setText(change_attribute.getName()
//							+ "-"
//							+ FormatUtil.onFormatTelephone(change_attribute
//									.getTel()));
//				}
//			}
//
//			break;
//		case MainAttribute.REQUEST_CODE_PERSON2:
//			if (data != null) {
//				change_attribute.setEnd_need_sms(data
//						.getIntExtra("need_sms", 1));
//				String name = data.getStringExtra("name");
//				String tel = data.getStringExtra("telephone");
//				if (name != null && tel != null && !name.equals("")
//						&& !tel.equals("")) {
//					change_attribute.setTel2(tel);
//					change_attribute.setName2(name);
//					tv_end_person.setText(change_attribute.getName2()
//							+ "-"
//							+ FormatUtil.onFormatTelephone(change_attribute
//									.getTel2()));
//					tv_end_person.setTextColor(Color.BLACK);
//				}
//			}
//
//			break;
//		case MainAttribute.REQUEST_CODE_START_ADDRESS:// 出发地
//			if (data != null) {
//				change_attribute.setStartName(data
//						.getStringExtra(AddressMsg.extra_address_name));
//				change_attribute.setStartCity(data
//						.getStringExtra(AddressMsg.extra_address_city));
//				change_attribute.setStartAddress(data
//						.getStringExtra(AddressMsg.extra_address_address));
//				change_attribute.setStartLongitude(data.getDoubleExtra(
//						AddressMsg.extra_address_longitude, 0));
//				change_attribute.setStartLatitude(data.getDoubleExtra(
//						AddressMsg.extra_address_latitude, 0));
//				if (!change_attribute.getStartName().equals("")) {
//					tv_start_address.setText(change_attribute.getStartName());
//				}
//			}
//			break;
//		case MainAttribute.REQUEST_CODE_END_ADDRESS:
//			if (data != null) {
//				change_attribute.setEndName(data
//						.getStringExtra(AddressMsg.extra_address_name));
//				change_attribute.setEndCity(data
//						.getStringExtra(AddressMsg.extra_address_city));
//				change_attribute.setEndAddress(data
//						.getStringExtra(AddressMsg.extra_address_address));
//				change_attribute.setEndLongitude(data.getDoubleExtra(
//						AddressMsg.extra_address_longitude, 0));
//				change_attribute.setEndLatitude(data.getDoubleExtra(
//						AddressMsg.extra_address_latitude, 0));
//				if (!change_attribute.getEndName().equals("")) {
//					tv_end_address.setText(change_attribute.getEndName());
//					tv_end_address.setTextColor(Color.BLACK);
//				}
//			}
//			break;
//		case MainAttribute.REQUEST_CODE_GOODS:
//			if (data != null) {
//
//				initAttribute();
//			}
//			break;
//		}
//		super.onActivityResult(requestCode, resultCode, data);
//	}
//
//	@Override
//	public void onContentFilling() {
//		if (isNull(change_attribute.getTime())
//				// && isNull(change_attribute.getName())
//				&& change_attribute.getIsCBclause()
//				&& isNull(change_attribute.getTel())
//				&& isNull(change_attribute.getStartName())
//				&& isNull(change_attribute.getStartLatitude())
//				&& isNull(change_attribute.getStartLongitude())
//				&& isNull(change_attribute.getName2())
//				&& isNull(change_attribute.getTel2())
//				&& isNull(change_attribute.getEndName())
//				&& isNull(change_attribute.getEndLatitude())
//				&& isNull(change_attribute.getEndLongitude())
//				&& isNull(change_attribute.getGoodsWeight())
//				&& isNull(change_attribute.getGoodsWeight())) {
//			btn_confirm.setEnabled(true);
//			btn_confirm.setTextColor(context.getResources().getColor(
//					R.color.white));
//		} else {
//			btn_confirm.setEnabled(false);
//			btn_confirm.setTextColor(context.getResources().getColor(
//					R.color.text_enabled));
//		}
//
//	}
//
//	public boolean isNull(String s) {
//		if (s != null && !s.equals(""))
//			return true;
//		return false;
//	}
//
//	public boolean isNull(Double s) {
//		if (s != null && s != 0)
//			return true;
//		return false;
//	}
//
//	public boolean isNull(Integer s) {
//		if (s != null && s != 0)
//			return true;
//		return false;
//	}
//
//	/**
//	 * 设置Elements，用于提交订单和获取价格
//	 */
//	public void setElements() {
//		elements = new ArrayList<Elements>();
//		elements.clear();
//		Elements mElements = new Elements();
//		// 出发地
//		Start start = new Start();
//		start.address = change_attribute.getStartName();
//		start.name = change_attribute.getName();
//		start.phone = change_attribute.getTel();
//		Location mLocation = new Location();
//		mLocation.lat = change_attribute.getStartLatitude();
//		mLocation.lng = change_attribute.getStartLongitude();
//		start.setLocation(mLocation);
//		// 目的地
//		End end = new End();
//		end.address = change_attribute.getEndName();
//		end.name = change_attribute.getName2();
//		end.phone = change_attribute.getTel2();
//		Location mLocation2 = new Location();
//		mLocation2.lat = change_attribute.getEndLatitude();
//		mLocation2.lng = change_attribute.getEndLongitude();
//		end.setLocation(mLocation2);
//		mElements.start = start;
//		mElements.end = end;
//		mElements.weight = change_attribute.getGoodsWeight();
//		mElements.volume = change_attribute.getGoodsVolume();
//		mElements.count = 1;
//		elements.add(mElements);
//	}
//
//	/**
//	 * 提交订单
//	 */
//	private void onOrderSubmit(int price) {
//		int travel_type = 0;
//		OrderSubmit mOrderSubmit = new OrderSubmit(context);
//		mOrderSubmit.uid = mApplication.getUid();
//		mOrderSubmit.access_token = mApplication.getToken();
//		mOrderSubmit.order_name = "test";
//		mOrderSubmit.price = price;
//		mOrderSubmit.old_order_id = old_order_id;
//		// order_name.open_id=
//		mOrderSubmit.tel = mApplication.user_phone;
//		mOrderSubmit.order_type = 2;// :0（拼车），1（包车）,2（货），3（市内叫车）
//		// mOrderSubmit.time=DateFormat.getCurrentTime();
//		mOrderSubmit.time = DateFormat.onDateAdd_ss(DateFormat.getCurrentTime());
//		mOrderSubmit.line_id = line_id;// 暂时测试，
//		if(change_attribute.getTime().equals(Value.now_time)){
//			mOrderSubmit.appoint_type = 0;
//		}
//		else{
//			mOrderSubmit.appoint_type = 1;
//		}
//		mOrderSubmit.travel_type = travel_type;
//		mOrderSubmit.appoint_time = DateFormat.onDateAdd_ss(change_attribute
//				.getTime());// 预约时间
//		mOrderSubmit.coupon_id = coupon_id;// 暂时不使用
//		mOrderSubmit.origin_type = 0;
//		// mOrderSubmit.service_uid="";
//		mOrderSubmit.order_message = change_attribute.getMessage_KJ();
//		
//		mOrderSubmit.elements = elements;
//		mChangeOrderSubmitTask = new ChangeOrderSubmitTask(this, mOrderSubmit,
//				travel_type, coupon_id);
//		mChangeOrderSubmitTask.execute();
//	}
//
//	public class ChangeOrderSubmitTask extends BaseAsyncTask {
//		private OrderSubmit mOrderSubmit;
//		private Activity context;
//		private int travel_type;
//		private int coupon_id;
//
//		public ChangeOrderSubmitTask(Activity context,
//				OrderSubmit mOrderSubmit, int travel_type, int coupon_id) {
//			super(context);
//			this.context = context;
//			this.mOrderSubmit = mOrderSubmit;
//			this.travel_type = travel_type;
//			this.coupon_id = coupon_id;
//		}
//
//		@Override
//		protected Object doInBackground(Object... params) {
//			// TODO Auto-generated method stub
//			String json = new JsonBuild().setModel(mOrderSubmit).getJson();
//			return new ChangeOrderSubmitNet(context, json);
//		}
//
//		@Override
//		public void onSuccess(Object object) {
//			if (object != null) {
//				// TODO Auto-generated method stub
//				ChangeOrderId mChangeOrderId = (ChangeOrderId) object;
//				Log.e("", "提交成功,订单Id为：" + mChangeOrderId.order_id);
//				Order mOrder = new Order(context);
//				mOrder.uid = mApplication.getUid();
//				mOrder.access_token = mApplication.getToken();
//				mOrder.order_id = mChangeOrderId.getOrderId();
//				onWriteDB_ing(mOrder.order_id, travel_type, coupon_id);
//			} else {
//				ToastUtil.showToast(context, "失败");
//			}
//		}
//
//		@Override
//		public void onFailed(int status, String msg) {
//			// TODO Auto-generated method stub
//			ToastUtil.showToast(context,
//					getResources().getString(R.string.no_network));
//		}
//	}
//
//	/**
//	 * 写入进行中的订单数据
//	 */
//	private void onWriteDB_ing(String order_id, int travel_type, int coupon_id) {
//		MyOrderList mMyOrderList = new MyOrderList();
//		// mMyOrderList.setId("");
//		mMyOrderList.setOrder_id(order_id);
//		mMyOrderList.setOrder_type(Value.ORDER_TYPE_KJ);
//		mMyOrderList.setAppoint_time(DateFormat.onDateAdd_ss(change_attribute
//				.getTime()));
//		mMyOrderList.setLine_id(line_id);
//		mMyOrderList.setTravel_type(travel_type);
//		mMyOrderList.setCoupon_id(String.valueOf(coupon_id));
//		mMyOrderList.setOrder_status(Value.ORDER_STATUS_UNTREATED);// 未处理
//		mMyOrderList.setValuate_status(String.valueOf(Value.VALUATE_STATUS_NO));// 待评价
//		mMyOrderList.setMessage(change_attribute.getMessage_KJ());
//		Locations mLocations = new Locations();
//		Start mStart = new Start();
//		mStart.setAddress(change_attribute.getStartName());
//		mStart.setName(change_attribute.getName());
//		mStart.setPhone(change_attribute.getTel());
//		Location mLocation_start = new Location();
//		mLocation_start.setLat(change_attribute.getStartLatitude());
//		mLocation_start.setLng(change_attribute.getStartLongitude());
//		mStart.setLocation(mLocation_start);
//		End end = new End();
//		end.setAddress(change_attribute.getEndName());
//		end.setName(change_attribute.getName2());
//		end.setPhone(change_attribute.getTel2());
//		Location mLocation_end = new Location();
//		mLocation_end.setLat(change_attribute.getEndLatitude());
//		mLocation_end.setLng(change_attribute.getEndLongitude());
//		end.setLocation(mLocation_end);
//		mLocations.setStart(mStart);
//		mLocations.setEnd(end);
//		mLocations.setCount(change_attribute.getCount());
//		mLocations.setVolume(String.valueOf(change_attribute.getGoodsVolume()));
//		mLocations.setWeight(String.valueOf(change_attribute.getGoodsWeight()));
//		mMyOrderList.setLocations(mLocations);
//		db_myordering.onWriteDB_ing(context, mMyOrderList);
//		db_myorder.onWriteDB(context, mMyOrderList);
//		db_myordering.onDelete(this, old_order_id);
//		db_myorder.onDelete(this, old_order_id);
//		db_address.onWrite(change_attribute.getStartName(), change_attribute.getStartCity(),change_attribute.getStartAddress(), change_attribute.getStartLongitude(), change_attribute.getStartLatitude(),Value.ADDRESS_TYPE_HISTORY);
//		db_address.onWrite(change_attribute.getEndName(), change_attribute.getEndCity(), change_attribute.getEndAddress(), change_attribute.getEndLongitude(), change_attribute.getEndLatitude(),Value.ADDRESS_TYPE_HISTORY);
//		// 存储在线消息数据
//		JmsgDB db_jmsg = new JmsgDB(context);
//		db_jmsg.onWrite(mMyOrderList.getOrder_id(), mMyOrderList.getOrder_time(), GMsg.ONLINE_XIADAN, null);
//		// 跳转到订单详情界面
//		Intent intent = new Intent(context, StartServiceActivity.class);
//		intent.putExtra(OrderMsg.extra_type, 0);
//		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//		startActivity(intent);
//	}
//
//	public void onDestroy() {
//		if (mApplication != null)
//			if (mChangeOrderSubmitTask != null
//					&& mChangeOrderSubmitTask.getStatus() != AsyncTask.Status.FINISHED)
//				mChangeOrderSubmitTask.cancel(true);
//		if (mCouponUsableTask != null
//				&& mCouponUsableTask.getStatus() != AsyncTask.Status.FINISHED)
//			mCouponUsableTask.cancel(true);
//		if (mPriceTask != null
//				&& mPriceTask.getStatus() != AsyncTask.Status.FINISHED)
//			mPriceTask.cancel(true);
//		super.onDestroy();
//
//	}
//
//	@Override
//	public void onPopViewState(boolean isOpen) {
//		if (isOpen) {
//			pop_background.setVisibility(View.VISIBLE);
//		} else {
//			pop_background.setVisibility(View.GONE);
//		}
//	}
//}
